package com.limbo.showapp.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.limbo.showapp.base.BasePresenter;
import com.limbo.showapp.base.BaseService;
import com.limbo.showapp.bean.RegisterBean;
import com.limbo.showapp.constant.AppConstant;
import com.limbo.showapp.presenter.RegisterPresenter;
import com.limbo.showapp.util.DisplayUtils;
import com.limbo.showapp.util.LogUtils;
import com.limbo.showapp.util.SPUtils;
import com.limbo.showapp.view.IHttpView;


/**
 * Created by wangqi on 2018/9/12.
 */

public class RegisterService extends BaseService<IHttpView, RegisterPresenter> implements IHttpView<RegisterBean> {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    protected RegisterPresenter getPresenter() {
        return new RegisterPresenter();
    }

    @Override
    public void onCreate() {
        super.onCreate();

        String deviceId = DisplayUtils.getDeviceId(this);
        LogUtils.e("服务开启 " + deviceId);

        mPresenter.register(deviceId);
    }

    @Override
    public void onSuccess(RegisterBean registerBean) {
        if (registerBean.getData() != null) {
            //注册成功
            RegisterBean.DataBean bean = registerBean.getData();
            SPUtils.setString(this, AppConstant.SP.USER_ID, bean.getId());
            SPUtils.setString(this, AppConstant.SP.USER_NAME, bean.getName());
            SPUtils.setString(this, AppConstant.SP.USER_HEAD_PIC, bean.getHeadPic());
            SPUtils.setString(this, AppConstant.SP.USER_IDENTIFICATION, bean.getIdentification());
            // TODO 剩余字段暂未使用
        }
    }

    @Override
    public void onError(String error) {

    }
}
